﻿#pragma once
#include "ZuiLib.h"
#include "LRefObject.h"
#include "LUtils.h"

namespace ZuiLib {

class LAnimateImage :public LRefObject<ZAnimateImage>
{
public:
	int loadFromFile(LuaFuncState& L)
	{
		return L.lreturn(pThis->LoadFromFile(L.arg(0).toString()));
	}

	int loadFromMem(LuaFuncState& L)
	{
		LuaObject ldata = L.arg(0);
		if (ldata.isUData())
		{
			return L.lreturn(pThis->LoadFromMem((uint8_t*)ldata.toPtr(), ldata.objLen()));
		}
		return 0;
	}

	//异步加载gif图片,注意selector是在非界面线程调用的
	//static void LoadAsync(const char* filePath, ZSchedulerBase *pTarget, SEL_SCHEDULE_GIF pfnSelector);

	int getSize(LuaFuncState& L)
	{
		return L.lreturn(toLua(&L,pThis->GetSize()));
	}

	int getFrameCount(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetFrameCount());
	}

	int getDurTime(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetDurTime());
	}

	int getWidth(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetWidth());
	}

	int getHeight(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetHeight());
	}


	BEGIN_MAP_FUNC(LAnimateImage)
	DECLARE_FUNC(loadFromFile),
	DECLARE_FUNC(loadFromMem),
	DECLARE_FUNC(getSize),
	DECLARE_FUNC(getFrameCount),
	DECLARE_FUNC(getDurTime),
	DECLARE_FUNC(getWidth),
	DECLARE_FUNC(getHeight),
	END_MAP_FUNC
};



class LAnimateImageControl :public LRefObject<ZAnimateImageControl>
{
public:
	int setImage(LuaFuncState& L)
	{
        ZAnimateImagePtr gif = LuaClass<ZAnimateImage>::luaToC(L.arg(0));
		pThis->SetImage(gif);
		return 0;
	}

	int setFile(LuaFuncState& L)
	{
		pThis->SetFile(L.arg(0).toString());
		return 0;
	}

	int setFileAsync(LuaFuncState& L)
	{
		pThis->SetFileAsync(L.arg(0).toString());
		return 0;
	}

	int setAutoSize(LuaFuncState& L)
	{
		pThis->SetAutoSize(L.arg(0).toBool());
		return 0;
	}

	BEGIN_MAP_FUNC(LAnimateImageControl)
	DECLARE_FUNC(setImage),
	DECLARE_FUNC(setFile),
	DECLARE_FUNC(setFileAsync),
	DECLARE_FUNC(setAutoSize),
	END_MAP_FUNC
};

}//namespace
